<?php if (!defined('BASEPATH')) exit('No direct script access allowed'); ?>
<?php 
	$ci = & get_instance();
	if(!isUserLogin()){
		redirect(site_url());exit();
	}
	$USER = $ci->user_entity->init('id',getUserId());
	
?>
<form action="<?php echo site_url('cricket/account/profile_submit');?>" name="profile_submit" id="profile_submit" method="post" enctype="multipart/form-data" >
<div id="center_content">

	<div class="clrboth"></div>
	<div class="block">
		<div class="title" style="position:relative;">
			<h3 class="bold"><a href="<?php echo site_url("cricket/user/dashboard")?>">Dashboard</a> &raquo; Profile</h3>
			<a class="back_button2" href="<?php echo site_url("cricket/user/dashboard")?>" title="Back?">Back?</a>	
		</div>
		<div class="clrboth"></div>
		<div class="content">
			<div class="rowitem3" style="position:relative;">
				<div style="position:absolute;left:70px;">
					<!--	
						<div class="grid2"><span class="bold">*Username:</span></div>
						<div class="grid6"><input type="text" value="<?php echo $USER->getUserName();?>" disabled="disabled" maxlength="45" id="username" name="username" class="std-input"/></div>
						<div class="grid2"><span class="bold red hidden" id="username_error">Required field.</span></div>
					-->
						<div class="grid2"><span class="bold">Username:</span></div>
						<div class="grid6"> <?php echo $USER->getUserName();?></div>
						<div class="clrboth"></div>
					<!--		
						<div class="grid2"><span class="bold">*Password:</span></div>
						<div class="grid6"><input type="password" maxlength="45" id="password" name="password" value="password" class="std-input"/></div>
						<div class="grid2"><span class="bold red hidden" id="password_error">Required field.</span></div>
					-->	
						<div class="clrboth"></div>
						
						
						<div class="clrboth"></div>
					<!--	
						<div class="grid2"><span class="bold">*Email:</span></div>
						<div class="grid6"><input type="text" disabled="disabled" maxlength="45" id="email" name="email" value="<?php echo $USER->getEmail();?>" class="std-input"/></div>
						<div class="grid2"><span class="bold red hidden" id="email_error">Required field.</span></div>
					-->	
						<div class="grid2"><span class="bold">Email:</span></div>
						<div class="grid6"> <?php echo $USER->getEmail();?></div>
						
						<div class="clrboth"></div>
						
						<div class="grid2"><span class="bold">*Full name:</span></div>
						<div class="grid6"><input type="text" maxlength="45" id="fullname" name="fullname" value="<?php echo $USER->getFullName();?>" class="std-input"/></div>
						<div class="grid2"><span class="bold red hidden" id="fullname_error">Required field.</span></div>
						
						<div class="clrboth"></div>
						
						<div class="grid2"><span class="bold">*Mobile:</span></div>
						<div class="grid6"><input type="text" maxlength="15" value="<?php echo $USER->getMobile();?>" id="mobile" name="mobile" class="std-input"/></div>
						<div class="grid2"><span class="bold red hidden" id="mobile_error">Required field.</span></div>
						
						<div class="clrboth"></div>
						
						<div class="grid2"><span class="bold">*Country:</span></div>
						<div class="grid6"><?php echo form_dropdown( 'country',
													$options = countriesOnTheWorldDataConfig(),
													$selected = array($USER->getCountry() ? $USER->getCountry() : 'India'),
													"id='country' style='margin:5px;width:255px;' class='std-input' "
												);	?></div>
						<div class="grid2"><span class="bold red hidden" id="country_error">Required field.</span></div>
						
						<div class="clrboth"></div>
						
						<div class="grid2"><span class="bold">State:</span></div>
						<div class="grid6"><input type="text" maxlength="45" value="<?php echo $USER->getState();?>" id="state" name="state" class="std-input"/></div>
						<div class="grid2"><span class="bold red hidden" id="state_error">Required field.</span></div>
						
						<div class="clrboth"></div>
						<div class="grid2"><span class="bold">City:</span></div>
						<div class="grid6"><input type="text" maxlength="45" value="<?php echo $USER->getCity();?>" id="city" name="city" class="std-input"/></div>
						<div class="grid2"><span class="bold red hidden" id="city_error">Required field.</span></div>
						
						<div class="clrboth"></div>
						<div class="grid2"><span class="bold">Avatar:</span></div>
						<div class="grid5">&nbsp;<?php echo form_upload('avatar');?></div>
						<div class="grid2"><?php if($USER->getAvatar()) echo thumb($USER->getMyAvatar(),60,60);?></div>
						<div class="clrboth"></div>
						
						<div class="grid2"><span class="bold">&nbsp;</span></div>
						<div class="grid6">&nbsp;<a href="<?php echo site_url("cricket/account/change_cod_info"); ?>" class="right" style="margin-right:100px;color:#333333;">Change COD information</a></div>
						<div class="clrboth"></div>
						
						<div class="grid2"><span class="bold">&nbsp;</span></div>
						<div class="grid6">&nbsp;<a href="<?php echo site_url("cricket/account/change_password"); ?>" class="right" style="margin-right:100px;color:#333333;">Change password</a></div>
						<div class="clrboth"></div>
						
						<div class="grid2"><span class="bold">&nbsp;</span></div>
						<div class="grid6">&nbsp;<a href="<?php echo site_url("cricket/account/change_email"); ?>" class="right" style="margin-right:100px;color:#333333;">Change email</a></div>
					
						<div class="clrboth"></div>
						<div class="grid2">&nbsp;</div>
						<div class="grid6"><input type="submit" class="submitclass" /> <?php echo loader_image('id="loader_image" class="hidden"');?></div>
						<div class="grid2"><span class="bold red hidden" id="submit_error">Missing.</span></div>	
						<?php echo form_hidden( "user_id", $USER->getId() ); ?>
						<div class="clrboth"></div>	
						
						<div class="grid2">&nbsp;</div>
						<div class="grid6" id="system_error"></div>

						<div class="clrboth"></div>	
				</div>		
			</div>	
			<div class="clrboth"></div>
		</div>
	</div>	
	<div class="clrboth"></div>
</div>	
</form>

<script type="text/javascript">
	google.setOnLoadCallback(function() {
		var option = { 
			beforeSubmit:  validateBeforeSubmit,  
			success: processAfterSubmit
		};	
		$('#profile_submit').ajaxForm(option);
	});
	
	function validateBeforeSubmit(formData, jqForm, options){
		$('#loader_image').show();
		var field_arr = new Array( 'fullname_error', 'mobile_error', 'country_error', 'state_error', 'city_error' );
		for(i in field_arr){
			$('#'+field_arr[i]).hide();
		}
		return true;
	}
	
	function processAfterSubmit(responseText, statusText, xhr, $form){
		$('#loader_image').hide();
		var p = new PHP_JS();
		var result_arr = p.explode('#',responseText); 
		if(result_arr[0] == 'msg'){
			$('#system_error').html(result_arr[1]).show();
			window.setTimeout('reload()',4000);
		}else if(result_arr[0] == 'err'){
			for(i in result_arr){
				$('#'+result_arr[i]).show();
			}
		}
	}
</script>